/*
 * COPYRIGHT. ShenZhen JiMi Technology Co., Ltd. 2017.
 * ALL RIGHTS RESERVED.
 *
 * No part of this publication may be reproduced, stored in a retrieval system, or transmitted,
 * on any form or by any means, electronic, mechanical, photocopying, recording, 
 * or otherwise, without the prior written permission of ShenZhen JiMi Network Technology Co., Ltd.
 *
 * Amendment History:
 * 
 * Date                   By              Description
 * -------------------    -----------     -------------------------------------------
 * 2017年7月6日    Li.Shangzhi         Create the class
 * http://www.jimilab.com/
 */

package com.jimi.samples.pay.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jimi.framework.base.BaseService;
import com.jimi.framework.utils.UUIDGenerator;
import com.jimi.samples.pay.dao.PayTokenMapper;
import com.jimi.samples.pay.model.PayTokenEntity;
import com.jimi.samples.pay.service.IPayTokenService;

/**
 * @FileName PayTokenServiceImpl.java
 * @Description:
 *
 * @Date 2017年7月6日 上午11:41:23
 * @author Li.Shangzhi
 * @version 1.0
 */
@Service
public class PayTokenServiceImpl extends BaseService implements IPayTokenService {

	@Resource
	private PayTokenMapper payTokenMapper;

	@Override
	public int findPageCount(PayTokenEntity payTokenEntity) {
		return payTokenMapper.findPageCount(payTokenEntity);
	}

	@Override
	public List<PayTokenEntity> findPage(PayTokenEntity payTokenEntity, RowBounds rowBounds) {
		return payTokenMapper.findPage(payTokenEntity, rowBounds);
	}

	@Override
	public List<PayTokenEntity> findList(PayTokenEntity payTokenEntity) {
		return payTokenMapper.findList(payTokenEntity);
	}

	@Override
	@Transactional
	public String insert(PayTokenEntity payTokenEntity) {
		String strId = UUIDGenerator.get32LowCaseUUID();
		payTokenEntity.setId(strId);
		PayTokenEntity entity = getNewPayInfo(payTokenEntity.getUserId());
		if (null == entity) {
			payTokenEntity.setMarkNum(1);
		} else {
			payTokenEntity.setMarkNum(entity.getMarkNum() + 1);
		}
		payTokenMapper.insert(payTokenEntity);
		return strId;
	}

	@Override
	@Transactional
	public int update(PayTokenEntity payTokenEntity) {
		return payTokenMapper.update(payTokenEntity);
	}

	@Override
	@Transactional
	public int remove(String id) {
		return payTokenMapper.remove(id);
	}

	@Override
	public PayTokenEntity getById(String id) {
		return payTokenMapper.getById(id);
	}

	@Override
	public PayTokenEntity getNewPayInfo(String userId) {
		return payTokenMapper.getNewOne(userId);
	}
}
